<?php require_once('../Connections/locale.php'); 

$colname_testo_email = "1";
if (isset($_POST['id_lettera'])) {
  $colname_testo_email = (get_magic_quotes_gpc()) ? $_POST['id_lettera'] : addslashes($_POST['id_lettera']);
}
mysql_select_db($database_locale, $locale);
$query_testo_email = sprintf("SELECT * FROM lettere_predefinite WHERE id_lettera = %s", $colname_testo_email);
$testo_email = mysql_query($query_testo_email, $locale) or die(mysql_error());
$row_testo_email = mysql_fetch_assoc($testo_email);
$totalRows_testo_email = mysql_num_rows($testo_email);

$query_ElencoEmails = $_POST['query'];
$ElencoEmails = mysql_query($query_ElencoEmails, $locale) or die(mysql_error());
$row_ElencoEmails = mysql_fetch_assoc($ElencoEmails);
$totalRows_ElencoEmails = mysql_num_rows($ElencoEmails);

//require_once('../includes/html2fpdf.php');

//error_reporting(1);

//$pdf = new HTML2FPDF();
//$pdf->DisableTags();
 $xml_output="";

 do { 

// $pdf->AddPage();
  $messaggio_temp = $row_testo_email['testo']; 
  $messaggio_temp = str_replace('#NOMINATIVO#',$row_ElencoEmails['nominativo'], $messaggio_temp);
  $messaggio_temp = str_replace('#RIVISTA#',$row_ElencoEmails['descrizione'], $messaggio_temp);
  $messaggio_temp = str_replace('#SCADENZA#',$row_ElencoEmails['data_scadenza'], $messaggio_temp);
  


$xml_output .=$messaggio_temp."<PAGE>";
//$pdf->WriteHTML($xml_output);
}  while ($row_ElencoEmails = mysql_fetch_assoc($ElencoEmails)); 



mysql_free_result($testo_email);

mysql_free_result($ElencoEmails);
//echo $xml_output;
//$pdf->WriteHTML($xml_output);
//$pdf->Output('stampe.pdf','D'); 
// Example use
include("./rtf/class_rtf.php");

$rtf = new rtf("./rtf/rtf_config.php");
$rtf->setPaperSize(5);
$rtf->setPaperOrientation(1);
$rtf->setDefaultFontFace(0);
$rtf->setDefaultFontSize(24);
$rtf->setAuthor("Abbonamenti");
//$rtf->setOperator("me@noginn.com");
$rtf->setTitle("Stampa Lettere");
//$rtf->addColour("#000000");
$rtf->addText($xml_output);
$rtf->getDocument();

?>
